package com.eflow.model.flowable.model.e;

import org.apache.commons.lang3.EnumUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author hui se
 * @description
 * @create 2021-03-05 17:45
 **/
public interface BaseEnum {
    /**
     * 获取编码
     * @return
     */
    int getCode();

    /** code转类
     * @param enumCode
     * @param clazz
     * @param <E>
     * @return
     */
    static <E extends BaseEnum> E codeOf(int enumCode, Class<E> clazz) {
        List<E> enumList = new ArrayList<>(Arrays.asList(clazz.getEnumConstants()));;
        for (E e : enumList) {
            E baseEnum = e;
            if(baseEnum.getCode()==enumCode){
                return  baseEnum;
            }
        }
        return null;
    }
}
